package com.neusoft.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neusoft.bean.Power;
import com.neusoft.service.PowerService;
import com.neusoft.service.impl.PowerServiceImpl;

import net.sf.json.JSONObject;

public class FindPowerServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		List<Power> powerlist = new ArrayList<>();
		PowerService  powerService = new PowerServiceImpl();
		powerlist = powerService.showPower();
		Map<String, Object> powerMap = new HashMap<>();
		powerMap.put("powerlist", powerlist);
		JSONObject json = JSONObject.fromObject(powerMap);
		PrintWriter out = resp.getWriter();
		out.println(json);
		out.flush();
		out.close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}
	
}
